<?php
/**
 * 商品多购优惠模型层
 * 
 * @copyright 	Copyright (c) 2011 thinkapk.com All rights reserved.
 * @package 	ThinkAPK_Model
 * @link 		http://www.thinkapk.com/
 * @author 		richie <richbossman@163.com>
 * @version 	$Id: GoodsDiscountModel.class.php 7474 2011-05-18 10:07:35Z richie $
 * 
 */
class GoodsDiscountModel extends CommonModel {
	
	/**
	 * 商品多购优惠商品页价格计算函数。促销商品除外
	 *
	 * @param int $goods_id
	 * @param int $goods_number
	 * @author richie
	 * 
	 * @return int
	 */
	function getGoodsDiscount($goods_id, $goods_number){
		if(!$goods_number || !$goods_id){
			return 0;
		}
		$row = $this->table($this->tablePrefix.'goods_discount AS D')
				->join($this->tablePrefix.'goods AS G')
				->field('D.goods_number, D.discount_price')
				->where('D.goods_id='.$goods_id." AND G.goods_id=D.goods_id AND G.is_promote=0")
				->find();
		if($row){
			if($row['goods_number'] && $row['goods_number'] <= $goods_number){
				return $row['discount_price'];
			}else{
				return 0;
			}
		}else{
			return 0;
		}
	}
}
?>